package com.example.myapplication;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class MyService extends Service {
    private MediaPlayer mediaPlayer;
    private MyBinder binder;
    public MyService() {
    }


    @Override
    public void onCreate() {

        super.onCreate();
        mediaPlayer=MediaPlayer.create(getApplicationContext(), R.raw.music1);
        mediaPlayer.start();
    }

    @Override
    public void onDestroy() {
        mediaPlayer.stop();
        super.onDestroy();

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        mediaPlayer.start();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
//        throw new UnsupportedOperationException("Not yet implemented");
        binder=new MyBinder();
        return binder;
    }

    class MyBinder extends Binder{
        public void myPlay(){
            Log.d("xr","Mybinder....");
            mediaPlayer=MediaPlayer.create(getApplicationContext(), R.raw.music1);
            mediaPlayer.start();
        }
    }


}